package org.autoparser.exttree.attributes;

import java.util.regex.Pattern;

import org.autoparser.filters.HasAttUsRegexFilter;
import org.htmlparser.NodeFilter;
import org.htmlparser.Tag;


public class ZExtRegexAttribute extends ZExtAttribute {
	public ZExtRegexAttribute(){
		super();
	}
	public ZExtRegexAttribute(final String attName){
		super(attName);
	}
	public ZExtRegexAttribute(final String attName,final String attValue){
		super(attName,attValue);
	}
	public ZExtRegexAttribute(ZExtAttribute att){
		super(att.getAttName(),att.getAttValue());
	}
	@Override
	public boolean isAttSatisfy(Tag tag, boolean caseSensitive) {
		String aName = tag.getAttribute(super.getAttName());
		if(aName == null)
			return false;
		else{
			Pattern pat = caseSensitive ? Pattern.compile(super.getAttValue()) : Pattern.compile(super.getAttValue(),Pattern.CASE_INSENSITIVE);
			return pat.matcher(aName).find();
		}
	}

	@Override
	public NodeFilter getFilter() {
		return new HasAttUsRegexFilter(super.getAttName(),super.getAttValue());
	}
}
